<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
  </head>
  <body>
    <div class="new-msg-list-div" id="new-msg-list-div">
      <div class="content-div">
        <div class="title" id="title">新消息</div>
        <div class="list-div" id="list-div"></div>
      </div>
      <div class="footer" onclick="onIgnoreAll()">忽略全部</div>
    </div>
  </body>
</html>
<script type="text/javascript">
  console.log('customNotice===============', window.electron)
  //监听electron消息
  window.electron.ipcRenderer.on('electron:list', (_, list) => {
    console.log('list===============', list)
    createListDom(list)
  })
  //获取标题dom
  const title = document.getElementById('title')
  //更新标题中的新消息总数量
  function updateTitleNumber(totalNumber) {
    title.innerHTML = '新消息（' + totalNumber + '）'
  }
  //获取存放列表的div
  const listDiv = document.getElementById('list-div')
  //清空列表dom
  function clearListDivDom() {
    while (listDiv.hasChildNodes()) {
      listDiv.removeChild(listDiv.firstChild)
    }
  }
  //创建列表dom
  function createListDom(listData) {
    clearListDivDom() //清空列表Dom
    let totalNumber = 0 //消息总数
    listData.forEach((item) => {
      //遍历列表数据创建dom节点
      const listItem = document.createElement('div')
      listItem.className = 'list-item'
      listItem.onclick = () => this.onRead(item)
      const content = document.createElement('div')
      content.className = 'content'
      const avatorDiv = document.createElement('div')
      avatorDiv.className = 'avator-div'

      const avator = document.createElement('img')
      avator.src = '../../resources/chat-mess.png'
      avator.className = 'avator-1'
      avatorDiv.append(avator)
      const nameDiv = document.createElement('div')
      nameDiv.className = 'name-div'
      const name = document.createElement('span')
      name.className = 'name'
      name.innerHTML = item.groupName
      content.append(avatorDiv)
      nameDiv.append(name)
      content.append(nameDiv)
      const msgNum = document.createElement('div')
      msgNum.className = 'msg-num'
      msgNum.innerHTML = item.unreadCount
      listItem.append(content)
      listItem.append(msgNum)
      listDiv.append(listItem)
      totalNumber += item.unreadCount //计算消息总数量
    })
    updateTitleNumber(totalNumber) //更新标题中的新消息总数量
  }

  //读取了某个聊天对象的消息
  function onRead(msg) {
    window.electron.ipcRenderer.send('electron:read', msg)
  }

  //点击 忽略全部 时触发
  function onIgnoreAll() {
    window.electron.ipcRenderer.send('electron:ignore')
  }
</script>
<style>
  body {
    margin: 0;
    padding: 0;
  }

  .new-msg-list-div {
    font-size: 12px;
    cursor: context-menu;
  }

  .new-msg-list-div .content-div {
    border-bottom: solid 1px #dedede;
  }
  .new-msg-list-div .content-div .title {
    line-height: 34px;
    font-weight: bold;
    padding: 0 20px;
  }
  .new-msg-list-div .content-div .list-div {
    max-height: 235px;
    overflow-y: auto;
    scrollbar-width: none; /*设置火狐浏览器不显示滚动条*/
  }

  .new-msg-list-div .content-div .list-div::-webkit-scrollbar {
    /*设置谷歌浏览器不显示滚动条*/
    width: 0;
    height: 0;
    background-color: transparent;
  }
  .new-msg-list-div .content-div .list-div .list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 20px;
    border-bottom: solid 1px #eee;
  }
  .new-msg-list-div .content-div .list-div .list-item:hover {
    background-color: #e8e8e8;
  }
  .new-msg-list-div .content-div .list-div .list-item .content {
    display: flex;
    align-items: center;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .avator-div {
    width: 34px;
    height: 34px;
    background-color: #eee;
    margin-right: 10px;
    display: flex;
    align-items: center;
    flex-wrap: wrap-reverse;
    justify-content: center;
    overflow: hidden;
    align-content: center;
    border-radius: 0px;
    flex-shrink: 0;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .avator-div .avator-1 {
    width: 100%;
    height: 100%;
    border-radius: 2px;
    font-size: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .avator-div .avator-2 {
    width: 46%;
    height: 46%;
    margin: 2%;
    font-size: 8px;
    line-height: 46%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .avator-div .avator-2 span {
    transform: scale(0.75);
    display: inline-block;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .avator-div .avator-3 {
    width: 30%;
    height: 30%;
    margin: 1%;
    font-size: 7px;
    line-height: 30%;
    zoom: 0.7;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .avator-div .avator-3 span {
    transform: scale(0.75);
    display: inline-block;
  }

  .new-msg-list-div .content-div .list-div .list-item .content .name-div {
    display: flex;
    align-items: center;
  }
  .new-msg-list-div .content-div .list-div .list-item .content .name {
    font-weight: bold;
    max-width: 90px;
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
  }
  .new-msg-list-div .content-div .list-div .list-item .msg-num {
    color: #fff;
    background-color: red;
    padding: 0 8px;
    border-radius: 100px;
  }
  .new-msg-list-div .footer {
    line-height: 34px;
    padding: 0 20px;
    text-align: right;
    color: #586cb1;
    cursor: pointer;
  }
</style>
